package com.bfxy.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableDiscoveryClient  //标识一个具体的服务，需要向注册中心注册
public class Application {
	
	@Bean
	@LoadBalanced // 具有服务发现的特性 走微服务的方式        @LoadBalanced 是一个负载均衡的机制，对provider的负载均衡。
	public RestTemplate restTemplete() {
		// @LoadBalanced 是去拉取服务列表，获得服务列表后，再跟具体的服务匹配
		HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = 
				new HttpComponentsClientHttpRequestFactory();
		clientHttpRequestFactory.setConnectTimeout(10000);// 链接超时
		clientHttpRequestFactory.setReadTimeout(10000);// 读 超时时间 	
		clientHttpRequestFactory.setConnectionRequestTimeout(10000);// 请求超时时间
		return new RestTemplate(clientHttpRequestFactory);
	}
	
	
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}
